

import { HvigorNode, HvigorPlugin, Json5Reader } from '@ohos/hvigor';
import { ModuleConfigurator } from './ModuleConfigurator';
import { CommonRouterModule } from './CommonRouterModule';
import path from 'path';
const PLUGIN_ID = "modularity-generate"

export class ModularityConfig {
    scanModules: ModuleConfig[] = [];
}

export class ModuleConfig {
    name: string | undefined
    scanPackages: string[] | undefined
    ignorePackages: string[] | undefined
}


export function ModularityPlugin(config?: ModularityConfig): HvigorPlugin {

    return {
        pluginId: PLUGIN_ID,
        apply(node: HvigorNode) {

            log("================================================================================");
            const projectPath = node.getNodePath()
            const projectName = path.basename(node.getNodePath())
            log("工程目录-" + projectPath);
            log("工程目录名-" + projectName);
            // 配置公共路由模块 
            CommonRouterModule.checkCreate(node, () => {
                // 配置模块项 修改模块下的 oh-package.json5 文件，关联上 公共路由模块
                ModuleConfigurator.configModule(node, config)

                log("================================================================================");
            })
        }
    }
}


export function log(msg: string) {
    console.log(PLUGIN_ID + "：" + msg)
}
